﻿using System;
using System.Collections.Generic;

namespace YJKStatisticTable.AreaTable.TableTools
{
	public class TableHeadCellKey
	{
		public TableHeadCellKey()
		{
		}

		public TableHeadCellKey(string keyName)
		{
			this.m_KeyName = keyName;
		}

		public TableHeadCellKey(TableHeadCellKey key)
		{
			this.m_KeyName = key.m_KeyName;
			this.m_CombinationOfAttributes.Clear();
			this.m_CombinationOfAttributes.AddRange(key.m_CombinationOfAttributes);
		}

		public TableHeadCellKey(string keyName, List<CombinationOfAttributes> combinationOfAttributes)
		{
			this.m_KeyName = keyName;
			this.m_CombinationOfAttributes.Clear();
			this.m_CombinationOfAttributes.AddRange(combinationOfAttributes);
		}

		public string KeyName
		{
			get
			{
				return this.m_KeyName;
			}
			set
			{
				this.m_KeyName = value;
			}
		}

		public List<CombinationOfAttributes> CombinationOfAttributes
		{
			get
			{
				return this.m_CombinationOfAttributes;
			}
			set
			{
				this.m_CombinationOfAttributes = value;
			}
		}

		public TableHeadCellKey._Tag_KeyType KeyType()
		{
			if (this.m_KeyName.CompareTo("") == 0)
			{
				return TableHeadCellKey._Tag_KeyType.HT_NULL;
			}
			if (this.m_CombinationOfAttributes.Count == 0)
			{
				return TableHeadCellKey._Tag_KeyType.HT_SINGLE;
			}
			return TableHeadCellKey._Tag_KeyType.HT_COMPOSITE;
		}

		public bool IsNull()
		{
			return this.KeyType() == TableHeadCellKey._Tag_KeyType.HT_NULL;
		}

		public bool FindAttributes2ndDelimitersByCategory(string categoryName, ref List<string> attributes, ref List<string> delimiters)
		{
			new List<string>();
			for (int i = 0; i < this.m_CombinationOfAttributes.Count; i++)
			{
				CombinationOfAttributes combinationOfAttributes = this.m_CombinationOfAttributes[i];
				if (combinationOfAttributes.CategoryName.CompareTo(categoryName) == 0)
				{
					attributes = combinationOfAttributes.AttributesName;
					delimiters = combinationOfAttributes.Delimiter;
					return true;
				}
			}
			return false;
		}

		public void RemoveAttributesByCategory(string categoryName)
		{
			new List<string>();
			for (int i = 0; i < this.m_CombinationOfAttributes.Count; i++)
			{
				CombinationOfAttributes combinationOfAttributes = this.m_CombinationOfAttributes[i];
				if (combinationOfAttributes.CategoryName.CompareTo(categoryName) == 0)
				{
					this.m_CombinationOfAttributes.RemoveAt(i);
					return;
				}
			}
		}

		private string m_KeyName = "";

		private List<CombinationOfAttributes> m_CombinationOfAttributes = new List<CombinationOfAttributes>();

		public enum _Tag_KeyType
		{
			HT_NULL = -1,
			HT_SINGLE,
			HT_COMPOSITE
		}
	}
}
